package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/dish")
public class DishCotroller {
    //注入service层
    @Autowired
    private DishService dishService;

    @ApiOperation("分页查询菜品的功能")
    @GetMapping("/page")
    public Result<PageResult> pageSelectDish(DishPageQueryDTO dishPageQueryDTO) {

        log.info("正在执行分页查询菜品的方法.....菜品为:{}", dishPageQueryDTO);

        //分页查询 一样的接收PageResult的对象
        PageResult p = dishService.pageSelectDish(dishPageQueryDTO);
        return Result.success(p);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品的功能")
    public Result<DishVO> selectById(@PathVariable Long id) {

        log.info("正在执行根据id查询菜品的方法....id为:{}", id);

        DishVO dish = dishService.selectById(id);
        return Result.success(dish);
    }

    @GetMapping("/list")
    @ApiOperation("根据分类查询菜品的功能")
    public Result<List<Dish>> selectByCategoryId(Integer categoryId) {

        log.info("正在执行根据分类查询菜品的方法.....分类为:{}", categoryId);

        List<Dish> dish = dishService.selectByCategoryId(categoryId);
        return Result.success(dish);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("菜品状态启停功能")
    public Result statusStartOrStop(@PathVariable Integer status, Long id) {

        log.info("正在执行菜品状态启停的方法 启动/暂停{},菜品id{}", status, id);

        dishService.statusStartOrStop(status, id);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改菜品信息")
    public Result updateDish(@RequestBody DishDTO dishDTO) {

        log.info("正在执行修改菜品信息的方法.......修改信息{}", dishDTO);

        dishService.updateDish(dishDTO);

        return Result.success();
    }

    @PostMapping
    @ApiOperation("新增菜品的功能")
    public Result insertDish(@RequestBody DishDTO dishDTO) {

        log.info("正在执行新增菜品的方法.....新增的菜品信息为:{}", dishDTO);

        dishService.insertDish(dishDTO);

        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("这是删除菜品的功能")
    public Result deleteDish(@RequestParam List<Long> ids) {

        log.info("正在执行删除菜品的功能......删除的菜品id为:{}", ids);

        dishService.deleteDish(ids);

        return Result.success();
    }

}
